package Zoo.Handler;


/*
 *  重要！！（配套Loginview）
 * */



import Zoo.Entity.ZooparkEntity;
import Zoo.Impl.LeaderServiceImpl;
import Zoo.Service.LeaderService;
import Zoo.View.LeaderView.LeaderView;
import Zoo.View.LeaderView.UpdateZooparkView;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UpdateZooparkViewHandler implements ActionListener {
    private UpdateZooparkView updateZooparkView;
    private LeaderView leaderView;

//    public AddAnimalViewHandler(AddZoomenView addZoomenView, LeaderView1 leaderView1){
//        this.addZoomenView=addZoomenView;
//        this.leaderView1=leaderView1;
//    }

    public UpdateZooparkViewHandler(UpdateZooparkView updateZooparkView, LeaderView leaderView) {
        this.updateZooparkView=updateZooparkView;
        this.leaderView=leaderView;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton=(JButton) e.getSource();
        String text =jButton.getText();
        if("修改".equals(text)){
            LeaderService leaderService=new LeaderServiceImpl();
            ZooparkEntity zooparkEntity =updateZooparkView.buildUpdatedZooparkEntity();
            boolean updateResult=leaderService.update(zooparkEntity);
            if(updateResult){
                //重新加载表格查到最新数据
                leaderView.reloadTable();
                updateZooparkView.dispose();
            }else{
                JOptionPane.showMessageDialog(updateZooparkView,"修改失败");

            }

        }
    }

}
